package com.miyake.client.datamanage;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Panel;
import com.miyake.client.DataService;
import com.miyake.client.DataServiceAsync;

public class ShowAlias {
	private DataServiceAsync service = DataService.Util.getInstance();
	
	public ShowAlias(final String key, final Panel panel) {
		service.getAlias(key, new AsyncCallback<Alias>() {
			@Override
			public void onFailure(Throwable caught) {
				Window.alert(caught.getMessage());
			}

			@Override
			public void onSuccess(Alias result) {
				dispatch(result, panel);
			}
		});
	}

	protected void dispatch(Alias result, Panel panel) {
		if (result.getType().equals(NodeProperty.PLOT)) {
			new ShowFixedPlot(result.getAliasKey(), panel, 400, 200) {
				@Override
				protected void onTextUpdate(String nodeKey) {

				}
			};
		}
		else if (result.getType().equals(NodeProperty.TABLE)) {
			new ShowFixedTable(result.getAliasKey(), panel);
		}
		else if (result.getType().equals(NodeProperty.IMAGE)) {
			new ShowImage(result.getAliasKey(), panel, null, null);
		}
	}
}
